package com.sgcc.statistics.controller;

import java.io.IOException;
import java.util.List;

import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.web.page.TableDataInfo;
import com.sgcc.common.datascope.annotation.DataScope;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sgcc.statistics.domain.OServiceIndex;
import com.sgcc.statistics.service.IOServiceIndexService;

import javax.servlet.http.HttpServletResponse;

/**
 * 服务成效指标维护Controller
 * 
 * @author sgcc
 * @date 2021-03-18
 */
@RestController
@RequestMapping("/OServiceIndex")
public class OServiceIndexController extends BaseController
{
    @Autowired
    private IOServiceIndexService oServiceIndexService;

    /**
     * 查询服务成效指标维护列表
     */
//    //@PreAuthorize(hasPermi=("statistics:OServiceIndex:list"))
    @GetMapping("/list")
    public TableDataInfo list(OServiceIndex oServiceIndex)
    {
        startPage();
        List<OServiceIndex> list = oServiceIndexService.selectOServiceIndexList(oServiceIndex);
        return getDataTable(list);
    }

    /**
     * 导出服务成效指标维护列表
     */
    //@PreAuthorize(hasPermi=("statistics:OServiceIndex:export"))
    @Log(title = "服务成效指标维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(HttpServletResponse response, OServiceIndex oServiceIndex) throws IOException {
        List<OServiceIndex> list = oServiceIndexService.selectOServiceIndexList(oServiceIndex);

        ExcelUtil<OServiceIndex> util = new ExcelUtil<OServiceIndex>(OServiceIndex.class);
        util.exportExcel(response, list, "OServiceIndex");
    }


    /**
     * 获取服务成效指标维护详细信息
     */
    //@PreAuthorize(hasPermi=("statistics:OServiceIndex:query"))
    @GetMapping(value = "/{code}")
    public AjaxResult getInfoByCode(@PathVariable("code") String code)
    {
        return AjaxResult.success(oServiceIndexService.selectOServiceIndexById(code));
    }


    /**
     * 新增服务成效指标维护
     */
    //@PreAuthorize(hasPermi=("statistics:OServiceIndex:add"))
    @Log(title = "服务成效指标维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OServiceIndex oServiceIndex)
    {
        return toAjax(oServiceIndexService.insertOServiceIndex(oServiceIndex));
    }

    /**
     * 修改服务成效指标维护
     */
    //@PreAuthorize(hasPermi=("statistics:OServiceIndex:edit"))
    @Log(title = "服务成效指标维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OServiceIndex oServiceIndex)
    {
        return toAjax(oServiceIndexService.updateOServiceIndex(oServiceIndex));
    }

    /**
     * 删除服务成效指标维护
     */
    //@PreAuthorize(hasPermi=("statistics:OServiceIndex:remove"))
    @Log(title = "服务成效指标维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oServiceIndexService.deleteOServiceIndexByIds(ids));
    }

    /**
     * 查询服务成效指标维护列表
     */
//    //@PreAuthorize(hasPermi=("statistics:OServiceIndex:list"))
    @GetMapping("/info/list")
    @DataScope(deptAlias = "o")
    public TableDataInfo listInfo(OServiceIndex oServiceIndex)
    {
//        startPage();
        List<OServiceIndex> list = oServiceIndexService.selectOServiceIndexInfoList(oServiceIndex);
        return getDataTable2(list);
    }

}
